using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Security;

namespace Main.handlers
{
    
    //We'll need this once we enable webservices.
    //For now, we won't.
    //That's cool, though, right?
    //[WebService(Namespace = "http://tempuri.org/")]
    //[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class vote : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.User.Identity.IsAuthenticated && context.Request.HttpMethod == "POST")
            {
                try
                {
                    DataAccess.CreateVote((Guid)Membership.GetUser().ProviderUserKey, Convert.ToInt32(context.Request.QueryString["id"]), Convert.ToInt32(context.Request[context.Request.QueryString["key"]]));
                    context.Response.Redirect("/polls/show.aspx?id=" + context.Request.QueryString["id"]);
                }
                catch (Exception)
                {
                    context.Response.Redirect("/polls/show.aspx?id=" + context.Request.QueryString["id"]);
                
                    //Handle this here...
                }
                
            }
            else
            {
                context.Response.Redirect("/default.aspx");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
